home *** CD-ROM | disk | FTP | other *** search
- /* Simple timer routine. Useful for timing the length of a program
- execution */
-
- #include "dos.h" /* dos interrupt routines */
- union REGS *inreg,*outreg; /* these are required for the intdos function */
-
- long _starttm; /* global for start time */
- long _stoptm; /* global for stopp time */
- long gettm(); /* returns time of day in seconds */
-
- /* This is a simple example of use of the timer. The start time is
- set, then the program waits for a key press, at which time it calls
- the stop time routine and prints the total time */
-
- main()
- {
- starttm();
- printf("timer started - press any key to stop\n");
- wait_key(); /* wait for a key press */
- printf("total time = %d sec\n",stoptm());
- }
-
-
- /* Set the start time */
- starttm()
- {
- _starttm = gettm(); /* sets global variable */
- }
-
- /* Get the stop time */
- int stoptm()
- {
- int time;
- _stoptm = gettm();
- time = (int) (_stoptm - _starttm); /* calculate time in seconds */
- return(time); /* return time as integer */
- }
-
- /* Returns long integer with time of day in seconds */
-
- long gettm()
- {
- int hour,minute,second,hund;
- long time;
- inreg->h.ah=0x2c; /* set get time interrupt */
- intdos(inreg,outreg); /* get time */
- hour = outreg->h.ch; /* read hour */
- minute = outreg->h.cl; /* read minute */
- second = outreg->h.dh; /* read seconds */
- hund = outreg ->h.dl; /* read hundreds */
-
- time = hour*3600 + minute*60 + second ; /* time in seconds */
- return(time);
- }
- wait_key()
- /* waits for key to be pressed */
- {
- inreg->h.ah = 0; /* set register to get key */
- int86(0x16,inreg,outreg); /* do interrupt */
- }
-
-